#pragma once

#include <sys_reg.h>

#define RCU_Q 0x40021000

typedef enum {
	RCU_CTL_R = 0x0,
	RCU_CFG0_R = 0x4,
	RCU_INT_R = 0x8,
	RCU_APB2RST_R = 0xC,
	RCU_APB1RST_R = 0x10,
	RCU_AHBEN_R = 0x14,
	RCU_APB2EN_R = 0x18,
	RCU_APB1EN_R = 0x1C,
	RCU_BDCTL_R = 0x20,
	RCU_RSTSCK_R = 0x24,
	RCU_AHBRST_R = 0x28,
	RCU_CFG1_R = 0x2C,
	RCU_DSV_R = 0x34,
} rcu_re;

static inline u32_s rcu_get_reg_q(rcu_re rcu_r, u32_s byte_r) {
	return RCU_Q + rcu_r + byte_r;
}

static inline void rcu_wreg(rcu_re rcu_r, u32_s value) {
	u32_s reg_q = rcu_get_reg_q(rcu_r, 0);
	wreg(reg_q, value);
}

static inline void rcu_wreg_u8(rcu_re rcu_r, t8b_re byte_r, u32_s value) {
	u32_s reg_q = rcu_get_reg_q(rcu_r, byte_r);
	wreg_u8(reg_q, value);
}

static inline void rcu_wreg_u16(rcu_re rcu_r, t16b_re byte_r, u32_s value) {
	u32_s reg_q = rcu_get_reg_q(rcu_r, byte_r);
	wreg_u16(reg_q, value);
}

static inline u32_s rcu_rreg(rcu_re rcu_r) {
	u32_s reg_q = rcu_get_reg_q(rcu_r, 0);
	return rreg(reg_q);
}

static inline u32_s rcu_rreg_u8(rcu_re rcu_r, t8b_re byte_r) {
	u32_s reg_q = rcu_get_reg_q(rcu_r, byte_r);
	return rreg_u8(reg_q);
}

static inline u32_s rcu_rreg_u16(rcu_re rcu_r, t16b_re byte_r) {
	u32_s reg_q = rcu_get_reg_q(rcu_r, byte_r);
	return rreg_u16(reg_q);
}
